package com.processor.base;

import com.handler.filter.HandlerFilter;
import com.handler.filter.HandlerFilterChain;
import com.handler.game.BaseHandler;

/**
 * @author : gameZhao
 * @version V1.0
 * @Project: disruptorDemo
 * @Package com.processor.base
 * @Description: 线程处理器模板
 * @date Date : 2021年12月27日 16:55
 */
public abstract class BaseProcessor {
    
    /**
     * 线程名字
     **/
    protected String processorName;
    
    public String getProcessorName() {
        return processorName;
    }
    
    /**
     * 过滤器链
     */
    private HandlerFilterChain filterChain;
    
    /**
     * 向processor提交事件
     *
     * @param handler
     */
    public void executeHandler(BaseHandler handler) {
        
        if (filterChain != null && !filterChain.process(handler)) {
            //TODO LOG
            return;
        }
        executeHandler0(handler);
    }
    
    ;
    
    /**
     * 向processor注册handler过滤器
     *
     * @param handlerFilter
     */
    public void registerFilter(HandlerFilter handlerFilter) {
        if(filterChain == null){
            filterChain = new HandlerFilterChain();
        }
        filterChain.registerFilter(handlerFilter);
    }
    
    public abstract void executeHandler0(BaseHandler handler);
    
    /**
     * @param isCompleteAllCommand
     * @return
     */
    public abstract boolean isStop(boolean isCompleteAllCommand);
    
    /**
     * @param await
     */
    public abstract void stop(boolean await);
    
    /**
     * @return
     */
    public abstract int getQueueSize();
    
    public abstract String getQueueInfo();
}
